package com.cskaoyan.javase.practice.stage7.utils;

import com.cskaoyan.javase.practice.stage7.entity.StudentList;

import java.io.*;

/**
 * @program: little-practice
 * @description:
 * @author: Keyu Li
 * @create: 2021-09-13 21:28
 **/

public class FileUtils {

    private FileUtils() {

    }

    public static StudentList getAllStuInfofromFile(File file) throws IOException {
        StudentList stul;
        try {
            stul = (StudentList) new ObjectInputStream(new FileInputStream(file)).readObject();
        } catch (Exception e) {
//            e.printStackTrace();
            return null;
        }
        return stul;


    }

    public static boolean writeStuInfotoFile(File file, StudentList stul) {
        try {
            new ObjectOutputStream(new FileOutputStream(file)).writeObject(stul);
        } catch (IOException e) {
            e.printStackTrace();
            return false;
        }
        return true;
    }
}
